﻿@section head{
    <style>

        .layui-card-body .layui-form-item {
            margin-bottom: 0px;
        }

        .layui-inline button {
            margin-right: 5px;
        }

        .layui-form-item .layui-input-inline {
            width: 200px;
            margin-right: 5px;
        }

        .layui-form-item .layui-inline {
            margin-right: 0;
        }

        @@media screen and (max-width:768px) {
            .layui-form-item .layui-input-inline {
                width: auto;
                margin-left: 5px;
            }

            .layui-inline button {
                margin-top: 5px;
            }
        }
/*        .layui-table-cell {
            text-align: center;
            height: auto;
            white-space: normal;
        }
        .layui-table img {
            max-width: 200px;
        }*/
    </style>
}
@section body {
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="filter-form" id="form1">
                <div class="layui-form-item">
                    <div class="layui-form-item layui-inline">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input class="layui-input" type="text" name="Customer" id="Customer" placeholder="客户名称" autocomplete="off" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" id="startEndDate" autocomplete="off" placeholder="日期范围" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select id="ResultStatus">
                                    @if (ViewBag.CoreTaskSchedulingLaunch == true)
                                    {
                                        <option value="-1">回复状态</option>
                                        <option value="1" selected>已回</option>
                                        <option value="0">未回</option>
                                    }
                                    else
                                    {
                                        <option value="-1">回复状态</option>
                                        <option value="1">已回</option>
                                        <option value="0" selected>未回</option>
                                    }

                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select id="ReadStatus">
                                    @if (ViewBag.CoreTaskSchedulingLaunch == true)
                                    {
                                        <option value="-1">读取状态</option>
                                        <option value="1">是</option>
                                        <option value="0" selected>否</option>
                                    }
                                    else
                                    {
                                        <option value="-1" selected>读取状态</option>
                                        <option value="1">是</option>
                                        <option value="0">否</option>
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">

                            <button type="button" class="pear-btn pear-btn-md pear-btn-primary" data-type="reload" id="btnSearch">
                                <i class="layui-icon layui-icon-search"></i>
                                查询
                            </button>
                            @if (ViewBag.CoreTaskSchedulingNew)
                            {
                                <button type="button" class="pear-btn pear-btn-primary pear-btn-md" data-type="add">
                                    <i class="layui-icon layui-icon-add-1"></i>
                                    新增
                                </button>
                            }
                            @if (ViewBag.CoreTaskSchedulingDelete)
                            {
                                <button type="button" class="pear-btn pear-btn-danger pear-btn-md" data-type="del">
                                    <i class="layui-icon layui-icon-add-1"></i>
                                    删除
                                </button>
                            }
                            <button type="reset" class="pear-btn pear-btn-md">
                                <i class="layui-icon layui-icon-refresh"></i>
                                重置
                            </button>
                        </div>
                    </div>
                </div>
            </form>
            <table id="task-table" lay-filter="task-table"></table>
        </div>
    </div>
    <script type="text/html" id="barDemo">

        <a class="layui-btn layui-btn-xs" lay-event="read">查看</a>
        {{#  if(d.ResultStatus ==21){ }}
        @if (ViewBag.CoreTaskSchedulingResult)
        {
            <a class="layui-btn layui-btn-xs" lay-event="result">回复</a>
        }
        {{#  } }}

    </script>
}
@section script {
    <script>
        var $;
        layui.use(['table', 'jquery', 'view', 'common'], function () {
            var table = layui.table
                , laydate = layui.laydate
                , view = layui.view;
            $ = layui.$;

            let common = layui.common;

            //日期范围
            laydate.render({
                elem: '#startEndDate'
                , range: '~'
            });

            //表格渲染
            table.render({
                elem: '#task-table'
                , url: 'GetTaskSchedulingListJson'
                , toolbar: false
                , defaultToolbar: false
                , autoSort: false
                , method: "post"
                , page: true
                , limit: 10
                , limits: [10,20, 50, 100]
                , height: 'full-130'
                , even: false
                , cols: [[
                    { type: 'numbers' }
                    , { type: 'checkbox' }
                    , { field: 'Customer', width: 150, title: '客户名称', sort: true }
                    , {
                        templet: function (d) {
                            if (d.Navigate_ResultStatus == null) {
                                return '';
                            } else {
                                return d.Navigate_ResultStatus.Name;
                            }
                        },
                        field: 'Navigate_ResultStatus.Name', width: 100, title: '回复状态', sort: true
                    }
                    , {
                        field: 'ReadStatus', width: 100, title: '回复读取', templet: function (d) {
                            if (d.ReadStatus === true) {
                                return '<span>是</span>';
                            } else {
                                return '<span style="color:red;">否</span>';
                            }
                        }, sort: false
                    }
                    , { field: 'LaunchAmount', width: 100, title: '发起金额', sort: false }
                    , { field: 'ReceiveAmount', width: 100, title: '回复金额', sort: false }
                    , {
                        field: 'LaunchPicUrl', width: 150, title: '发起图片', templet: function (d) {
                            return '<img src="' + d.LaunchPicUrl + '" style/>';
                        }, sort: false
                    }
                    , {
                        field: 'ReceivePicUrl', width: 150, title: '回复图片', templet: function (d) {
                            if (d.ReceivePicUrl==null) {
                                return '';
                            } else {
                                return '<img src="' + d.ReceivePicUrl + '" style/>';
                            }
                        }, sort: false
                    }
                    , { field: 'LaunchRemark', width: 200, title: '发起备注', sort: false }
                    , { field: 'ReceiveRemark', width: 200, title: '回复备注', sort: false }
                    , {
                        templet: function (d) {
                            if (d.Users_Launch == null) {
                                return '';
                            } else {
                                return d.Users_Launch.ChineseName;
                            }
                        },
                        field: 'Users_Launch.ChineseName', width: 100, title: '发起人', sort: true
                    }
                    , { field: 'LaunchTime', width: 160, title: '发起时间', sort: false }
                    , {
                        templet: function (d) {
                            if (d.Users_Receive == null) {
                                return '';
                            } else {
                                return d.Users_Receive.ChineseName;
                            }
                        },
                        field: 'Users_Receive.ChineseName', width: 100, title: '接收人', sort: true
                    }
                    , { field: 'ResultTime', width: 160, title: '回复时间', sort: false }
                    , { field: 'ResultReadTime', width: 160, title: '回复读取时间', sort: false }
                    , { fixed: 'right',title: '操作', toolbar: '#barDemo', width: 120 }
                ]]
                , where: {
                    Customer: $('#Customer').val(),
                    startEndDate: $('#startEndDate').val(),
                    ReadStatus: $('#ReadStatus').val(),
                    ResultStatus: $('#ResultStatus').val(),
                    __RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value
                }
                ,done: function (res, curr, count) {
                    // 该方法用于解决,使用fixed固定列后,行高和其他列不一致的问题
                    //$(".layui-table-main  tr").each(function (index, val) {
                    //    $($(".layui-table-fixed .layui-table-body tbody tr")[index]).height($(val).height());
                    //});
                }
            });
            var active;
            $('.layui-inline .pear-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            //监听排序事件
            table.on('sort(task-table)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                table.reload('task-table', {
                    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                    , where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                        Customer: $('#Customer').val(),
                        startEndDate: $('#startEndDate').val(),
                        ReadStatus: $('#ReadStatus').val(),
                        ResultStatus: $('#ResultStatus').val()
                        , field: obj.field //排序字段
                        , order: obj.type //排序方式
                    }
                });
            });
            //重载事件
            active = {
                reload: function () {
                    table.reload('task-table', {
                        page: {
                            curr: 1
                        }
                        , where: {
                            Customer: $('#Customer').val(),
                            startEndDate: $('#startEndDate').val(),
                            ReadStatus: $('#ReadStatus').val(),
                            ResultStatus: $('#ResultStatus').val()
                        }
                    });
                },
                add: function () {
                    top.layer.open({
                        type: 2,
                        resize: false,
                        id: 'iframe1',
                        content: '/TaskCenter/TaskSchedulingNew',
                        area: common.isModile() ? ['95%', '95%'] : ['720px', '720px'],
                        end: function (index, layero) {
                            btnSearchClick();
                        }
                    });
                },
                del: function () {
                    var checkStatus = table.checkStatus('task-table')
                        , data = checkStatus.data; //获取选中的数据
                    if (data.length === 0) {
                        layer.msg('至少选择一行', {
                            offset: 't',
                            anim: 6
                        });
                        return;
                    }
                    var ids = new Array();
                    for (var i = 0; i < data.length; i++) {
                        ids[i] = data[i].Id
                    }

                    top.layer.confirm('真的要删除么？', function (index) {
                        top.layer.load(0, {
                            shade: [0.5, '#fff'] //0.1透明度的白色背景
                        });
                        //请求登入接口
                        view.req({
                            url: 'DeleteTaskScheduling' //实际使用请改成服务端真实接口
                            , data: { ids: ids, __RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value }
                            , type: "post"
                            , dataType: "json"
                            , done: function (res) {
                                if (res.codeIndex == 1) {
                                    top.layer.closeAll('loading'); //关闭loading
                                    layer.msg('删除' + res.msg, {
                                        offset: '15px'
                                        , icon: 1
                                        , time: 1000
                                    });
                                    //在顶层弹出需要手动关闭
                                    top.layer.close(index);
                                    btnSearchClick();
                                } else {
                                    top.layer.closeAll('loading'); //关闭loading
                                    top.layer.close(index);
                                    layer.msg(res.msg, {
                                        offset: 't',
                                        anim: 6
                                    });
                                }
                            }
                        });
                    });
                }
            };


            //监听行工具事件
            table.on('tool(task-table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'result') {
                    top.layer.open({
                        type: 2,
                        resize: false,
                        id: 'iframe3',
                        content: '/TaskCenter/TaskSchedulingResult?id=' + data.Id,
                        area: common.isModile() ? ['95%', '95%'] : ['1100px', '90%'],
                        end: function (index, layero) {
                            btnSearchClick();
                        }
                    });
                }
                else if (obj.event === 'read') {
                    top.layer.open({
                        type: 2,
                        resize: false,
                        id: 'iframe3',
                        content: '/TaskCenter/TaskSchedulingRead?id=' + data.Id,
                        area: common.isModile() ? ['95%', '95%'] : ['1100px', '90%'],
                        end: function (index, layero) {
                            btnSearchClick();
                        }
                    });
                }
                return false;
            });
        });

        document.onkeydown = function (e) {
            if (!e) e = window.event;
            if ((e.keyCode || e.which) === 13) {
                //document.getElementById("login_button").focus();

                // 查找你要判断的文本框
                var myInput = document.getElementById('Customer');
                if (myInput === document.activeElement) {
                    //获得焦点后查询
                    document.getElementById("btnSearch").click();
                }

            }
        }
        //查询事件
        function btnSearchClick() {
            document.getElementById("btnSearch").click();
        }
    </script>
}